package com.briup.test;

/**
 * @author 甜圆
 * @version v1.0.1
 * @date 2025/9/24 9:15
 * @package com.briup.test
 * @copyright 甜圆
 */
public class Test23 {

}


class Writer implements Cloneable{
    private int age;
    private String name;

    // getter/setter 和构造方法都已省略

    @Override
    public String toString() {
        return "com.briup.test.Writer{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }


    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Writer(int age, String name) {
        this.age = age;
        this.name = name;
    }
}



class TestClone {
    public static void main(String[] args) throws CloneNotSupportedException {
        Writer writer1 = new Writer(18,"二哥");
        Writer writer2 = (Writer) writer1.clone();

        System.out.println("浅拷贝后：");
        System.out.println("writer1：" + writer1);
        System.out.println("writer2：" + writer2);

        writer2.setName("三妹");

        System.out.println("调整了 writer2 的 name 后：");
        System.out.println("writer1：" + writer1);
        System.out.println("writer2：" + writer2);
    }
}